package Decorator.cashier;

/**
 * @author duanzhizhou
 * @date 2024/9/25
 */
public class BuyOneGetOneCashier extends CashDecorator {
    
    public BuyOneGetOneCashier(Cashier cashier) {
        super(cashier);
    }
    
    @Override
    public double check(double price, int cnt) {
        double total = super.check(price, cnt);
        double newPrice = total / cnt;
        cnt -= cnt / 2;
        if (total == 0d) {
            return price * cnt;
        }
        return newPrice * cnt;
    }
}
